const bankCardFormat = value => {
    return value.substr(-4, 4);
}

const phoneFormat = value => {
        return value.substr(0, 3) + '****' + value.substr(-4, 4);
    }
    // 日期过滤器分开取
const dateToTime = (value, type) => {
        let date = new Date(value * 1000);
        if (type === 'time') {
            return (date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours()) + ':' + (date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date.getMinutes());
        } else if (type === 'month') {
            return (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月';
        } else if (type === 'date') {
            return date.getDate()
        }
    }
    // 多少时间之前
const timeFormate = value => {
        let nowTime = Date.parse(new Date()) / 1000;
        let timeDifference = (nowTime - value);
        if (timeDifference >= 0 && timeDifference < 60) {
            return timeDifference + '秒之前';
        } else if (timeDifference >= 60 && timeDifference < 3600) {
            return Math.floor(timeDifference / 60) + '分钟之前';
        } else if (timeDifference >= 3600 && timeDifference < 86400) {
            return Math.floor(timeDifference / 3600) + '小时之前';
        } else if (timeDifference >= 86400 && timeDifference < 31536000) {
            return Math.floor(timeDifference / 86400) + '天之前';
        } else {
            return Math.floor(timeDifference / 31536000) + '年之前';
        }
    }
    // 返回完整时间
const timeToDate = value => {
    let date = new Date(value * 1000);
    return date.getFullYear() + '-' + (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-' + (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ' +
        (date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours()) + ':' + (date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date.getMinutes());
}

export {
    bankCardFormat,
    phoneFormat,
    dateToTime,
    timeFormate,
    timeToDate,
}